package org.zzz.utils;

/**
 * @Author ZZF
 * @Time 2021/04/20 21:24
 */
public class Result<T> {
    private int status;

    private String message;

    private T data;

    public Result(){
    }

    public Result(int status,String message,T data){
        this.status = status;
        this.message = message;
        this.data = data;
    }

    public Result(ResultEnum resultEnum,T data){
        this.status = resultEnum.getStatus();
        this.message = resultEnum.getMessage();
        this.data = data;
    }

    public static Result success(String message){
        return new Result(ResultEnum.SUCCESS.getStatus(), message,null);
    }

    public static Result error(String message){
        return new Result(ResultEnum.ERROR.getStatus(), message,null);
    }

    public Result data(T data){
        this.data = data;
        return this;
    }

    public int getStatus() {
        return status;
    }

    public String getMessage() {
        return message;
    }


    public T getData() {
        return data;
    }

    @Override
    public String toString() {
        return "Result{" +
                "status=" + status +
                ", message='" + message + '\'' +
                ", data=" + data +
                '}';
    }
}
